{extend name="base" /}
{block name="body"}
<div class="layui-card">
	<div id="echarts" style="height: 300px"></div>
	<div class="layui-card-header">
		<form id="techForm" action="{:url('admin/collection/scientificIndex')}" class="layui-form" method="get">
			<div class="layui-form-item">
				<div class="layui-input-inline">
					归属学院
					<select id="secondaryCollege" name="secondaryCollege">
						<option value="">全部机构</option>
						<option value="信息学院">信息学院</option>
						<option value="金融管理学院">金融管理学院</option>
						<option value="理学院">理学院</option>
						<option value="艺术学院">艺术学院</option>
					</select>
				</div>
				<div class="layui-input-inline">
					成果级别
					<input type="text" id="level" name="level" value="{:input('level')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-input-inline">
					赞助基金
					<select id="projectFund" name="projectFund">
						<option value="">全部机构</option>
						<option value="信息学院">国家自然基金</option>
						<option value="金融管理学院">国家社科基金</option>
					</select>
				</div>
				<div class="layui-input-inline">
					时间
					<input type="text" id="yearFrom" name="yearFrom" value="{:input('yearFrom')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-input-inline">
					到
					<input type="text" id="yearTo" name="yearTo" value="{:input('yearTo')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-input-inline">
					作者姓名
					<input type="text" id="creator" name="creator" value="{:input('creator')}" autocomplete="off" class="layui-input"/>
				</div>
				<div class="layui-input-inline" style="width: 50px;">
					<button class="layui-btn layui-btn-primary ajax-search"><i class="fa fa-search"></i></button>
				</div>
			</div>
		</form>
	</div>
	<div class="layui-card-body">
        <div class="layui-btn-group">
		    <a onclick="dataExport()" class="layui-btn"><i class="fa fa-plus-circle"></i> 导出</a>
        </div>
		<table class="layui-table layui-form">
			<thead>
			<tr>
				<th>编号</th>
				<th>项目名称</th>
				<th>项目主持人</th>
				<th>项目级别</th>
				<th>赞助基金</th>
				<th>公开时间</th>
			</tr>
			</thead>
			<tbody>
			{foreach name="list" item="v" empty="$empty"}
			<tr>
				<td>{$v.projectNo}</td>
				<td>{$v.title}</td>
				<td>{$v.creator}</td>
				<td>{$v.projectFund}</td>
				<td>{$v.level}</td>
				<td>{$v.publicationDate}</td>
			</tr>
			{/foreach}
			</tbody>
		</table>
		<div class="page">{$list->render()}</div>
	</div>
</div>
{/block}
{block name="js"}
<script>
	laydate.render({
		elem: '#yearFrom',
		type: 'year'
	})
	laydate.render({
		elem: '#yearTo',
		type: 'year'
	})

	$(function() {
		initChart();
	});

	function initChart() {
		$.ajax({
			url: '/admin/collection/scientificChartIndex',
			type: 'POST',
			dataType: 'json',
			success: function(result) {
				if (result.code === 1) {
					var years = result.data.years;
					if (years.length <= 0) {
						return
					}
					var line = [];
					var yline = [];
					for (i = 0; i < years.length; i++) {
						line[i] = years[i].year;
						yline[i] = years[i].count;
					}
					var chartDom = document.getElementById('echarts');
					var myChart = echarts.init(chartDom);
					var option;
					option = {
						xAxis: {
							type: 'category',
							data: line
						},
						yAxis: {
							type: 'value'
						},
						series: [{
								data: yline,
								type: 'line'
							}],
						tooltip : {
							trigger: 'axis',
							axisPointer: {
								type: 'cross',
								label: {
									backgroundColor: '#6a7985'
								}
							}
						}
					}
					option && myChart.setOption(option);
				} else {
					layer.msg(result.msg);
				}
			},
			error: function (xhr, state, errorThrown) {
				layer.msg(state + '：' + errorThrown);
			}
		});
	}

	function dataExport() {
		var formData = $('#techForm').serialize();
		$.ajax({
			url: '/admin/collection/scientificExport',
			type: 'POST',
			data: formData,
			success: function (result) {
				location.href = '/' + result.data.url
				layer.msg('导出成功');
			},
			error: function (xhr, state, errorThrown) {
				layer.msg(state + '：' + errorThrown);
			}
		});
	}
</script>
{/block}